package inet.app.view.slidemenu;



import inet.app.R;
import inet.app.view.slidemenu.SlideMenuItem.SlideMenuItemType;

import java.util.List;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class SlideMenuArrayAdapter extends ArrayAdapter<SlideMenuItem> {

	private List<SlideMenuItem> slideMenuItemList;

    public SlideMenuArrayAdapter( Context context, int textViewResourceId, List<SlideMenuItem> slideMenuItemList) {
    	
        super( context, textViewResourceId, slideMenuItemList);
        this.slideMenuItemList = slideMenuItemList;            
    }
    
    @Override
    public View getView( int position, View view, ViewGroup parent) {
    	
    	SlideMenuItem slideMenuItem = slideMenuItemList.get( position);
    	LayoutInflater layoutInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	
    	if( slideMenuItem.getSlideMenuItemType() == SlideMenuItemType.Header){
    		
    		view = layoutInflater.inflate( R.layout.menu_header_listview_item, null);          
                    
            TextView textView = (TextView) view.findViewById( R.id.MenuListHeaderListViewItem_text);           
            textView.setText( slideMenuItem.getText());
    		
    	}
    	else if( slideMenuItem.getSlideMenuItemType() == SlideMenuItemType.Activity){
    		view = layoutInflater.inflate( R.layout.menu_activity_listview_item, null);            
            ImageView imageview = (ImageView) view.findViewById(R.id.imageview);
            imageview.setBackgroundResource(slideMenuItem.getImgview());
            TextView textView = (TextView) view.findViewById( R.id.MenuActivityListViewItem_text);
	        textView.setText(slideMenuItem.getText());
    	}
    	else{
    		view = null;	//Left for operation 
    	}
    	
        return view;
    }    
}
